<template>
    <view class="pub_page pub_page_bg pub_wallet_recharge pub_header_padding">
        <pub-head headerName="wallet_recharge" :headerConfig="headerConfig" @headerBack="headerBack"></pub-head>
        <pub-dialog v-show="dialogShow" dialogName="wallet_recharge" :dialogConfig="dialogConfig"
            @dialogBack="dialogBack"></pub-dialog>
        <div class="pub_page_scroll page_box">
            <div class="pub_inputs">
                <div class="abox">
                    <div class="ali ali_1">
                        <div class="atitle ainput_right_icon">USDT</div>
                    </div>
                    <div class="ali ali_1">
                        <div class="atitle ainput_right_icon">充值网络 TRC20</div>
                    </div>
                    <div class="ali ali_2">
                        <div class="atitle">充值地址</div>
                        <div class="atxt">
                            <div class="atxt_1" @click="$comFun.toCopy(rechargeConfig.address)">复制</div>
                        </div>
                        <input class="ainput" type="text" :placeholder="rechargeConfig.address" disabled />
                    </div>
                    <div class="ali ali_2">
                        <div class="atitle">请填写哈希值</div>
                        <div class="atxt">
                            <div class="atxt_2">如不填写可能无法到账</div>
                        </div>
                        <textarea class="atextarea" v-model="transactionId" placeholder="交易流水ID"></textarea>
                    </div>
                    <div class="ali">
                        <div class="atitle">充值金额</div>
                        <input class="ainput" v-model="num" type="text" placeholder="请输入充值金额" />
                    </div>
                </div>
            </div>
            <br>
            <br>
            <div class="pub_btn" @click="walletDeal('to_recharge')">提交</div>
            <br>
            <br>
        </div>
    </view>
</template>

<script>
export default {
    data() {
        return {
            pagescrollTop: 0,
            headerConfig: {
                title: '充值',//标题栏内容
                left_type: 3,
                right_type: 1,//右侧区域类型  0不出现  1文字  2图片
                right_content: '充值记录',//右侧内容  right_type为1时文字内容 为2时图片链接
            },

            dialogShow: false,
            dialogType: '',
            dialogData: '',
            dialogConfig: {
                // title: 'demo',//标题栏内容
                content: '',
            },

            rechargeConfig: {
                address: '',
                min: 0,
            },


            num: "",
            transactionId: "",
        };
    },
    onLoad() {
        this.getRechargeConfig();
    },
    onPageScroll(res) {
        this.pagescrollTop = res.scrollTop;
    },
    methods: {
        headerBack(data) {
            if (data.name == 'wallet_recharge' && data.type == 'right') {
                this.$comFun.openWin('/pages/mine/usdt_log', { openType: 'recharge' });
            }
        },
        dialogBack(data) {
            // console.log(data);
            this.dialogShow = false;
            if (data.name == 'wallet_recharge' && data.key == 1) {
                let obj = {
                    'walletRecharge': 'sure_recharge',
                }
                this.walletDeal(obj[this.dialogType])
            }
        },
        // 获取充值配置
        async getRechargeConfig() {
            let configRes = await getApp().getConfigList();
            this.rechargeConfig.address = configRes.rechargeUsdtAddress;
        },
        async walletDeal(type, info, key) {
            switch (type) {
                case 'to_recharge':
                    if (this.transactionId == '') {
                        this.$comFun.toast('请输入交易流水ID');
                        return;
                    }
                    if (this.num == '' || !this.$comFun.ValidateNum(this.num)) {
                        this.$comFun.toast('请输入正确的充值数量');
                        return;
                    }
                    this.dialogType = 'walletRecharge';
                    this.dialogShow = true;
                    this.dialogConfig = {
                        content: '是否确定充值？',
                    };
                    break;
                case 'sure_recharge':
                    this.$comFun.openLoading();
                    const res_2 = await this.$request.post('user/submitRechargeApply', {
                        num: this.num,
                        transactionId: this.transactionId,
                    });
                    this.$comFun.closeLoading();
                    this.$comFun.toast(res_2.message);
                    if (res_2.code == 200) {
                        this.num = '';
                        this.transactionId = '';
                    }
                    break;
            }
        }
    },
};
</script>

<style lang="scss" scoped>
@import "@/common/css/mine.scss";
</style>
